﻿
$(document).ready(function() {
    if (jQuery.url.param("Id") != undefined) {
        id = jQuery.url.param("Id");
    }
    JSUtility.url = '../Handler/AjaxHandle.ashx';
    JSUtility.param = { AssemblyName: "OA.Bll.Personnel", ClassName: "OA.Bll.Personnel.EducationViewPresenter", Method: "Search", Options: {} };
    top.autoResize({ dataGrid: '#Grid', callback: InitEducationViewlist, par: {}, method: 'Paged' });
    $('#btnSubmit,#btnCancel').linkbutton();
    $("#btnAdd").bind("click", function() {
        Initlist();
        $("#employeeWin").window("open");
    });
    $("#btnDel").click(function() {
        Del();
    });
    $("#btnSubmit").click(function() {
        Add();
    });
    $('#btnCancel').click(function() {
        $("#employeeWin").window("close");
    });
    // Initlist();
});

function Del() {
    var ids = [];
    var rows = $('#Grid').datagrid('getSelections');
    for (var i = 0; i < rows.length; i++) {
        ids.push(rows[i].EmployeeId);
    }
    if (ids.length > 0) {
        var p = { AssemblyName: "OA.Bll.Personnel", ClassName: "OA.Bll.Personnel.EmployeeEducationMappingPresenter", Method: "Delete", Options: {} };
        p.Options["id"] = ids.join(';');
        p.Options["EducationId"] = id;
        $.ajax({
            type: "post",
            url: '../Handler/AjaxHandle.ashx',
            data: $.toJSON(p),
            dataType: "json",
            success: function(data) {
                if (data.flag) {
                    //$('#Grid').datagrid('reload');
                    $.messager.show({ msg: data.msg, title: "info" });
                   
                    location.reload();
                   
                } else {
                    $.messager.alert('错误', data.msg, 'error');
                }
            }
        });
    } else {
        $.messager.alert('系统提示', '选择删除的员工!', 'info');
    }
}

//添加参训人员信息
function Add() {
    var ids = [];
    var rows = $('#employeeList').datagrid('getSelections');
    for (var i = 0; i < rows.length; i++) {
        ids.push(rows[i].Id);
    }
    if (ids.length > 0) {
        var p = { AssemblyName: "OA.Bll.Personnel", ClassName: "OA.Bll.Personnel.EmployeeEducationMappingPresenter", Method: "Add", Options: {} };
        p.Options["id"] = ids.join(';');
        p.Options["EducationId"] = id;
        $.ajax({
            type: "post",
            url: '../Handler/AjaxHandle.ashx',
            data: $.toJSON(p),
            dataType: "json",
            success: function(data) {
                if (data.flag) {
                    $('#Grid').datagrid('reload');
                   
                    $.messager.show({ msg: data.msg, title: "info" });
                    $("#employeeWin").window("close");
                } else {
                    $.messager.alert('错误', data.msg, 'error');
                }
            }
        });
    } else {
        $.messager.alert('系统提示', '选择要参训的员工!', 'info');
    }
}
var id;
function InitEducationViewlist(op, method, size) {
    var p = JSUtility.param;
    p.Options["Id"] = id;
    JSUtility.grid = $('#Grid').datagrid({
        width: 700,
        height: 500,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        striped: true,
        queryParams: { "json": $.toJSON(p) },
        url: JSUtility.url,
        frozenColumns: [[{ field: 'ck', checkbox: true}]]
    });
}

function Initlist() {
    var p = { AssemblyName: "OA.Bll.Personnel", ClassName: "OA.Bll.Personnel.EmployeePresenter", Method: "Paged", Options: {} };
    $('#employeeList').datagrid({
        width: 700,
        height: 400,
        pageSize: 10,
        striped: true,
        queryParams: { "json": $.toJSON(p) },
        url: '../Handler/AjaxHandle.ashx',
        frozenColumns: [[{ field: 'ck', checkbox: true}]]

    });
}